/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Modelo;

import Controlador.ConnectionDB;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * Clase Diseñada para cargar datos específicos de la base de datos.
 * @author Gitecx
 * @since 1.0
 * @see Visitar http://gitecx.unillanos.edu.co/
 */
public class Querys {
    /**
     * @return Retorna una lista con dos elementos de la tabla server: ServerPath y ManagerEmail
     */
    public static List<String> ServerData(){
        List<String> Data = new ArrayList<String>();        
        ConnectionDB c = new ConnectionDB();          
        if(c.Connect()){
            ResultSet result = c.getQuery("SELECT serverpath, manageremail from server;"); 
        try {
            result.next();          
            Data.add(result.getString(1));
            Data.add(result.getString(2));
        } catch (Exception e) {
            System.err.println("Error en Modelo.Querys ServerData: "+ e.getMessage());
            Data.add("");
            Data.add("");
        }finally{
            c.close();
        }
        }
        else{
            System.err.println("Error en Modelo.Querys ServerData: No se pudo Conectar a la Base de Datos");
            Data.add("");
            Data.add("");
        }
        return Data;
        
    }
    
    public static ResultSet ResultAsigPlugInc(String idplugin){
        ResultSet retorno = null;
        ConnectionDB c = new ConnectionDB();
        if(c.Connect()){
            retorno = c.getQuery("select A.name, B.name, C.idpluginincident from plugin A, incident B, pluginincident C where c.plugin = "+idplugin+" and A.idplugin = C.plugin and B.idincident = C.incident;");            
            c.Connect();
        }
        return retorno;
    }
    
    public static String DecodeString(String string){
        try{
        return new String(string.getBytes("ISO-8859-1"),"UTF-8");
        }catch(Exception e){
            return string;
        }
    }
    
    public static String CheckDB(){
        boolean connect = false;
        ConnectionDB c = new ConnectionDB();
        connect = c.Connect();
        c.close();
        if (!connect){
            return "new Messi('No se pudo conectar a la base de datos', {title: 'Error', autoclose: '3000', titleClass: 'error anim', buttons: [{id: 0, label: 'Cerrar', val: 'X'}]});";
        }else{
            return "";
        }
    }
}